package moc.zard.xg.service.impl;

import moc.zard.xg.Repository.IPersonD;
import moc.zard.xg.pojo.Person;
import moc.zard.xg.service.IPersonrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
@CacheConfig(cacheNames = "IPersonrService")
public class PersonServiceImpl implements IPersonrService {

    @Autowired
    private IPersonD IPersonD;

    @Override
    public Person save(Person person) {
        Person save = IPersonD.save(person);
        return save;
    }

    @Override
    public Person findByName(String name) {
        return IPersonD.findPersonByPersonPameEquals(name);
    }

    @Override
    public Person findById(Integer id) {
        Optional<Person> _person = IPersonD.findById(id);
        return Optional.ofNullable(_person).get().orElse(null);
    }
}
